package com.cqc.nestedrecyclerview01;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";
    private RecyclerView recyclerView;
    private Context context = this;
//    private List<StudentBean> studentList = new ArrayList<>();
    private List<StudentBean> studentList ;
    private List<ClassBean> classList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);


        initData();
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        MyAdapter adapter = new MyAdapter(classList);
        recyclerView.setAdapter(adapter);
    }

    private void initData() {
        for (int i = 0; i < 30; i++) {
            ClassBean classBean = new ClassBean();
            classBean.setClassName("班级" + i);

            studentList= new ArrayList<>();
//            studentList.clear();//采用clear()无法全部清除，
            int maxValue = new Random().nextInt(5);
            for (int j = 0; j < maxValue; j++) {
                StudentBean student = new StudentBean();
                student.setName("小明"+(j+1));
                student.setAge("15");
                studentList.add(student);
            }

            classBean.setStudents(studentList);
            classList.add(classBean);
        }
    }
}
